<?php

namespace app\common\model\scroll;

use think\Model;


class Notify extends Model
{

    // 表名
    protected $table = 'scroll_notify';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        "text"
    ];

    public static function log($name, $nickname, $type, $is_virtually = 0)
    {
        return self::create([
            'name' => $name,
            'nickname' => $nickname,
            'type' => $type,
            'is_virtually' => $is_virtually
        ]);
    }

    //增加横幅记录

    public function getTextAttr($value, $data)
    {
        $type_text = "";
        switch ($data['type']) {
            case 0:
                $type_text = "恭喜 {$data['nickname']},完成{$data['name']}";
                break;
            case 1:
                $type_text = "恭喜 {$data['nickname']},成功兑换{$data['name']}";
                break;
            case 2:
                $type_text = "恭喜 {$data['nickname']},抽奖{$data['name']}";
                break;
        }
        return $type_text;
    }

    public function getTypeList()
    {
        return [0 => '任务', 1 => '兑换', 2 => '抽奖'];
    }
}
